<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<jsp:include page="common/header.jsp">
    <jsp:param name="title" value="购物车"/>
    <jsp:param name="customCss" value="shop_cart"/>
</jsp:include>

<div class="container">
    <h1 class="page-title">购物车</h1>
    <div class="cart-items">
        <c:forEach items="${cartItems}" var="item">
            <div class="cart-item">
                <c:choose>
                    <c:when test="${not empty item.imageUrl}">
                        <img src="${item.imageUrl}" alt="${item.name}" class="product-image">
                    </c:when>
                    <c:otherwise>
                        <img src="${pageContext.request.contextPath}/image/noproduct.png" alt="${item.name}"
                             class="product-image">
                    </c:otherwise>
                </c:choose>
                <div class="item-details">
                    <h3>${item.name}</h3>
                    <p class="price">¥${item.price}</p>
                    <div class="quantity-control">
                        <button onclick="updateQuantity(${item.goodsId}, -1)">-</button>
                        <span>${item.quantity}</span>
                        <button onclick="updateQuantity(${item.goodsId}, 1)">+</button>
                    </div>
                </div>
                <button class="remove-btn" onclick="removeItem(${item.goodsId})">删除</button>
            </div>
        </c:forEach>
    </div>

    <div class="cart-summary">
        <div class="total">总计: <span>¥${total}</span></div>
        <div class="actions">
            <a href="${pageContext.request.contextPath}/toCheckoutServlet" class="checkout-btn">结算</a>
            <a href="${pageContext.request.contextPath}/shopListServlet" class="continue-shopping-btn">继续购物</a>
        </div>
    </div>
</div>

<jsp:include page="common/footer.jsp">
    <jsp:param name="customJs" value="shop_cart"/>
</jsp:include>
